import axios from 'axios'
// import Qs from 'qs'

const request = axios.create({
//   baseURL: '127.0.0.1:5000', // api 的 base_url
  baseURL: 'http://localhost:5000', // api 的 base_url
  timeout: 10000
  // headers:{'Content-Type':'application/x-www-form-urlencoded'}
})
request.interceptors.request.use(config => {
    // NProgress.start()
    console.log(config)
    // if(config.method == "post"){
    //   config.data = Qs.stringify(config.data)
    // }
    const token = sessionStorage.getItem('token')
    config.headers.Authorization = 'Bearer ' + token
    return config
  },
  error => ({ status: 0, msg: error.message })
  )
  // 响应拦截
  request.interceptors.response.use(response => {
    // NProgress.done()
    return Promise.resolve(response)
  },
  error => {
    return Promise.reject(error)
  }
  )
export default request
